package com.cxh.rmsq.net.self

import androidx.lifecycle.MutableLiveData
import com.aleyn.mvvm.base.BaseViewModel
import com.cxh.rmsq.db.model.AddressBean
import com.cxh.rmsq.db.model.AuthenticationBean
import com.cxh.rmsq.db.model.MineBean


class AllViewModel : BaseViewModel() {

    private val repository by lazy { InjectorUtil.getRepository() }

    public val getSendSmsCode = MutableLiveData<BaseResult<Any>>()

    //    public val getSmsLogin = MutableLiveData<BaseResult<LoginBean?>>()
//    public val getLogin = MutableLiveData<BaseResult<LoginBean?>>()
    public val getLogout = MutableLiveData<BaseResult<Any?>>()
    public val setAuthentication = MutableLiveData<BaseResult<Any?>>()
    public val getAuthentication = MutableLiveData<BaseResult<AuthenticationBean?>>()
    public val getUserUpdate = MutableLiveData<BaseResult<Any?>>()
    public val getProvinceList = MutableLiveData<BaseResult<ArrayList<AddressBean>>>()
    public val getCityList = MutableLiveData<BaseResult<ArrayList<AddressBean>>>()
    public val getAreaList = MutableLiveData<BaseResult<ArrayList<AddressBean>>>()
    public val getUserInfo = MutableLiveData<BaseResult<MineBean?>>()
    public val getFileUpdate = MutableLiveData<BaseResult<String?>>()
    public val changePwd = MutableLiveData<BaseResult<Any?>>()
    public val changePhone = MutableLiveData<BaseResult<Any?>>()


    /**
     * 融云
     * ----------------------------------------------------------------------------------------------------------------------------
     */
//    public val getRCRegister = MutableLiveData<RCBaseResult<RCRegisterBean>>()
//    public val getFindUser = MutableLiveData<RCBaseResult<RCFindUserBean>>()
//    public val getFriendAll = MutableLiveData<RCBaseResult<ArrayList<FriendShipInfo>>>()
//    public val getFindUserList = MutableLiveData<RCBaseResult<RCFindUserBean>>()


    fun getSendSmsCode(phone: String): MutableLiveData<BaseResult<Any>> {
        val mapOf = hashMapOf<String, Any>()
        mapOf.put("scene", 1)
        mapOf.put("mobile", phone)
        mapOf.put("region", "+86")
        launchGo({
            getSendSmsCode.value = repository.getSendSmsCode(mapOf)
        })
        return getSendSmsCode
    }

//    fun getSmsLogin(phone: String, code: String, region: String): MutableLiveData<BaseResult<LoginBean?>> {
//        val mapOf = hashMapOf<String, Any>()
//        mapOf.put("code", code)
//        mapOf.put("mobile", phone)
//        mapOf.put("region", region)
//        launchGo({
//            getSmsLogin.value = repository.getSmsLogin(mapOf)
//        }, {
//            getSmsLogin.value = BaseResult(it.errMsg, it.code, null)
//        })
//        return getSmsLogin
//    }
//
//    fun getLogin(phone: String, password: String): MutableLiveData<BaseResult<LoginBean?>> {
//        val mapOf = hashMapOf<String, Any>()
//        mapOf.put("mobile", phone)
//        mapOf.put("password", password)
//        launchGo({
//            getLogin.value = repository.getLogin(mapOf)
//        }, {
//            getLogin.value = BaseResult(it.errMsg, it.code, null)
//        })
//        return getLogin
//    }

    fun getLogout(): MutableLiveData<BaseResult<Any?>> {
        val mapOf = hashMapOf<String, Any>()

        launchGo({
            getLogout.value = repository.getLogout(mapOf)
        }, {
            getLogout.value = BaseResult(it.errMsg, it.code, null)
        })
        return getLogout
    }

    fun setAuthentication(
        id: String,
        realName: String,
        idNumber: String,
        zmPhoto: String,
        fmPhoto: String
    ): MutableLiveData<BaseResult<Any?>> {
//        var userId: Int by SPreference(Constant.USER_ID, 0)
        val mapOf = hashMapOf<String, Any>()
        mapOf.put("userId", "userId")
        mapOf.put("id", id)
        mapOf.put("realName", realName)
        mapOf.put("idNumber", idNumber)
        mapOf.put("zmPhoto", zmPhoto)
        mapOf.put("fmPhoto", fmPhoto)
        launchGo({
            setAuthentication.value = repository.setAuthentication(mapOf)
        })
        return setAuthentication
    }

    fun getAuthentication(): MutableLiveData<BaseResult<AuthenticationBean?>> {
//        var userId: Int by SPreference(Constant.USER_ID, 0)
        launchGo({
            getAuthentication.value = repository.getAuthentication(0/*"userId"*/)
        })
        return getAuthentication
    }

    fun getUserUpdate(mapOf: HashMap<String, Any>): MutableLiveData<BaseResult<Any?>> {

        launchGo({
            getUserUpdate.value = repository.getUserUpdate(mapOf)
        })
        return getUserUpdate
    }

    fun getProvinceList(): MutableLiveData<BaseResult<ArrayList<AddressBean>>> {

        launchGo({
            getProvinceList.value = repository.getProvinceList()
        })
        return getProvinceList
    }

    fun getCityList(code: String): MutableLiveData<BaseResult<ArrayList<AddressBean>>> {
        launchGo({
            getCityList.value = repository.getCityList(code)
        })
        return getCityList
    }

    fun getAreaList(code: String): MutableLiveData<BaseResult<ArrayList<AddressBean>>> {

        launchGo({
            getAreaList.value = repository.getAreaList(code)
        })
        return getAreaList
    }

    fun getUserInfo(userId: String): MutableLiveData<BaseResult<MineBean?>> {

        launchGo({
            getUserInfo.value = repository.getUserInfo(userId)
        })
        return getUserInfo
    }

    fun getFileUpdate(img: String): MutableLiveData<BaseResult<String?>> {
        launchGo({
            getFileUpdate.value = getPart("file", img)?.let { repository.getFileUpdate(it) }
        })
        return getFileUpdate
    }

    fun changePwd(password: String): MutableLiveData<BaseResult<Any?>> {
        val mapOf = hashMapOf<String, Any>()
        mapOf.put("password", password)
        launchGo({
            changePwd.value = repository.changePwd(mapOf)
        })
        return changePwd
    }

    fun changePhone(code: String, mobile: String): MutableLiveData<BaseResult<Any?>> {
        val mapOf = hashMapOf<String, Any>()
        mapOf.put("code", code)
        mapOf.put("mobile", mobile)
        launchGo({
            changePhone.value = repository.changePhone(mapOf)
        })
        return changePhone
    }


    /**
     *  -----------------------------------------------------------------------------------------------------------------------
     * 融云接口
     */
    /* fun getRCRegister(): MutableLiveData<RCBaseResult<RCRegisterBean>> {
         var userId: Int by SPreference(Constant.USER_ID, 0)
         var phoneNumber: String by SPreference(Constant.PHONE, "")
         var portraitUri: String by SPreference(Constant.PORTRAIT_URI, "")
         var nickName: String by SPreference(Constant.NICK_NAME, "")
         val mapOf = hashMapOf<String, Any>()
         mapOf.put("region", REGION)
         mapOf.put("phone", phoneNumber)
         mapOf.put("nickname", nickName)
         mapOf.put("userId", userId.toString())
         mapOf.put("portraitUri", portraitUri)
         mapOf.put("code", "")
         mapOf.put("os", "android")
         mapOf.put("version", BuildConfig.VERSION_NAME)
         launchGo({
             getRCRegister.value = repository.getRCRegister(mapOf)
         })
         return getRCRegister
     }

     fun getFindUser(phone: String): MutableLiveData<RCBaseResult<RCFindUserBean>> {

         val mapOf = hashMapOf<String, Any>()

 //        if (!TextUtils.isEmpty(name)) {
 //            mapOf.put("st_account", name);
 //        } else {
 //
 //        }
         mapOf.put("region", "86");
         mapOf.put("phone", phone);
         launchGo({
             getFindUser.value = repository.getFindUser(mapOf)
         })
         return getFindUser
     }


     fun getFriendAlls(): MutableLiveData<RCBaseResult<ArrayList<FriendShipInfo>>> {

         launchGo({
             getFriendAll.value = repository.getFriendAlls()
         })
         return getFriendAll
     }

     fun getFindUserList(phone: String,region: String): MutableLiveData<RCBaseResult<RCFindUserBean>> {

         launchGo({
             getFindUserList.value = repository.getFindUserList(phone,region)
         })
         return getFindUserList
     }*/
}
